package com.cy.pj.sys.service.impl;

import com.cy.pj.sys.dao.SysNoticeDao;
import com.cy.pj.sys.pojo.SysNotice;
import com.cy.pj.sys.service.SysNoticeService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.sql.SQLException;
import java.util.List;

/**
 * 公告业务 具体实现
 * 1）核心业务（调用数据层方法操作数据）
 * 2）拓展业务（日志信息，权限控制，事务控制，缓存....）
 */
@Slf4j
@Service//@Component
public class
SysNoticeServiceImpl implements SysNoticeService {
//被@Slf4j替代,会自动创建log对象
//   private static final Logger log=
//          LoggerFactory.getLogger(SysNoticeServiceImpl.class);

    //@Autowired
    private SysNoticeDao sysNoticeDao;
    public SysNoticeServiceImpl(SysNoticeDao sysNoticeDao){
        this.sysNoticeDao=sysNoticeDao;
    }
    @Override
    public List<SysNotice> findNotice(SysNotice sysNotice)  {
        long t1=System.currentTimeMillis();//日志，记录时间
        log.info("method start {}",t1);
        List<SysNotice> list=sysNoticeDao.selectNotice(sysNotice);
        long t2=System.currentTimeMillis();
        log.info("method start {}",t2);
        return list;
    }

    @Override
    public int saveNotice( SysNotice sysNotice) {
        int rows=sysNoticeDao.insertNotice(sysNotice);
        return rows;
    }

    @Override
    public SysNotice findById(Long id) {

        return sysNoticeDao.selectById(id);
    }

    @Override
    public int updateNotice(SysNotice sysNotice) {

        return sysNoticeDao.updateNotice(sysNotice);

    }

    @Override
    public int deleteById(Long... id) {
        int row=sysNoticeDao.deleteById(id);
        if(row==0){
            throw new ServiceException("该记录可能不存在");
        }
        return row;
    }
}
